import { getDictItemsFromCache } from '@/api/api'
import Api from '@/api/sjsk/performanceServiceQuery'

const examineReview = {
  data() {
    return {
      labelCol: { span: 6 },
      wrapperCol: { span: 17 },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '计划编号',
          align: "center",
          dataIndex: 'planCode'
        },
        {
          title: '计划名称',
          align: "center",
          dataIndex: 'planName',
        },
        {
          title: '考核类型',
          align: "center",
          dataIndex: 'assessmentType',
          customRender: (text, record, index) =>
            `${this.setTittle(record)}`
        },
        {
          title: '考核周期',
          align: "center",
          dataIndex: 'assessmentCycle'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '考核单位',
          align: "center",
          dataIndex: 'assessmentUnit'
        },
        {
          title: '指标名称',
          align: 'center',
          dataIndex: 'indicatorName'
        },
        {
          title: '考核对象',
          align: 'center',
          dataIndex: 'assessmentUser'
        },
        {
          title: '考核得分',
          align: 'center',
          dataIndex: 'assessmentScore'
        },{
          title: '复议申请时间',
          align: 'center',
          dataIndex: 'reconsiderationTime'
        },
        {
          title: '复议分数',
          align: 'center',
          dataIndex: 'reconsiderationScore'
        },
        {
          title: '复议缘由',
          align: 'center',
          dataIndex: 'esType_dictText6'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'reconsiderationType', // 提交、未提交、审核通过、审核不通过
          customRender: (text, record, index) =>
            `${this.setStatus(record)}`
        },
        {
          title: '复议审核时间',
          align: 'center',
          dataIndex: 'reconExamineTime'
        },
        {
          title: '审核意见',
          align: 'center',
          dataIndex: 'reconExamineReason'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      examinType: getDictItemsFromCache('examinType'),
      examinStatus: getDictItemsFromCache('reviewStatus'),
      loading: false,
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      queryParam:{},
      checkList:[],
      pageData: {},
      componentName:'', // reviewApply,myReviewExamine,examCheck,
      fuyiStatus:'', // 1未提交，2已提交，3审批通过，4审批未通过
    }
  },
  created(){
    this.componentName = this.$route.meta.componentName;
    this.onQuery()
  },
  methods: {
    setTittle(val) {
      return this.$filterDictTextByCache('examinType', val.assessmentType) //现在字典中对应的文字，考核类型
    },
    setStatus(val){
      this.fuyiStatus = val.reconsiderationType;
      return this.$filterDictTextByCache('reviewStatus', val.reconsiderationType) //现在字典中对应的文字，考核状态
    },
    // 查询
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    // 重置
    onResetForm() {
      this.queryParam = {}
      this.pageFilter = {
        pageNo: 1,
        pageSize: 10
      }
      this.refreshTable()
    },
    onSelectedRow(keys) {
      this.checkList = keys;
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      this.loading = true
      let params = Object.assign({}, this.queryParam, this.pageFilter)
      let interfaceMethod = null;
      if(this.componentName === 'reviewApply'){
        interfaceMethod = Api.appleAssessmentList(params)
      }else if(this.componentName === 'examCheck'){
        interfaceMethod = Api.auditAssessmentList(params)
      }else{
        interfaceMethod = Api.mineAssessmentList(params)
      }
      interfaceMethod.then((res) => {
        if (res.success) {
          this.pageData = res.result ? res.result : {}
          this.loading = false
          this.$refs.table.onClearRowKeys()
        } else {
          this.loading = false
          this.pageData = {}
          this.$message.warn('请求失败！')
        }
      }).catch((e) => {
        this.loading = false
        this.$message.warn('请求失败！')
      })
    },
    onDetail(record) {
      this.$router.push({
        path: "/examineReview/applyDialog",
        query: {
          id: record.id,
          type:this.componentName,
          fuyiStatus:this.fuyiStatus
        }
      })
    },
  }
}
export default examineReview